//
//  NextSecondRowTableViewCell.m
//  LT
//
//  Created by dllo on 16/5/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "NextSecondRowTableViewCell.h"
#import "NextSecondCollectionViewCell.h"

@interface NextSecondRowTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic,strong)UICollectionView *nextCollectionView;

@end

@implementation NextSecondRowTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCollectionView];
    }
    return self;

}

-(void)createCollectionView{

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake(200 * WIDTHCELL, 130 * WIDTHCELL);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.nextCollectionView = [[UICollectionView alloc]initWithFrame:self.contentView.bounds collectionViewLayout:flowLayout];
    self.nextCollectionView.backgroundColor = [UIColor clearColor];
    self.nextCollectionView.delegate = self;
    self.nextCollectionView.dataSource = self;
    //取消collectionView来回滑的效果
    self.nextCollectionView.scrollEnabled = NO;
    [self.nextCollectionView registerClass:[NextSecondCollectionViewCell class] forCellWithReuseIdentifier:@"nextCell"];
    [self.contentView addSubview:self.nextCollectionView];
    
}

//item数量
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 2;
}


//什么时候需要从新布局子视图
-(void)layoutSubviews{
    [super layoutSubviews];

    self.nextCollectionView.frame = CGRectMake(5* WIDTHCELL, 5* WIDTHCELL, (self.contentView.frame.size.width - 15), (self.contentView.frame.size.height - 15));
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    NextSecondCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"nextCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    if (self.dataArray.count != 0) {
        cell.subjectModel = self.dataArray[indexPath.row + 1];
    }
    
    return cell;

}

//点击方法

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    self.nextStationBlock(indexPath.row);
}




//使用数组传值
-(void)setTempArray:(NSMutableArray *)tempArray{
    
    _tempArray = tempArray;
    
    self.dataArray = [NSMutableArray arrayWithArray:_tempArray];
    
    
    [self.nextCollectionView reloadData];


}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
